home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / Multiprocessing.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  7.6 KB  |  326 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Multiprocessing.h
  3.  
  4.      Contains:    Multiprocessing interfaces
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1996-1998 by Apple Computer, Inc. and © 1995-1997 DayStar Digital, Inc.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __MULTIPROCESSING__
  18. #define __MULTIPROCESSING__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23. #ifndef __CODEFRAGMENTS__
  24. #include <CodeFragments.h>
  25. #endif
  26.  
  27. #include <stdarg.h>
  28.  
  29.  
  30. #if PRAGMA_ONCE
  31. #pragma once
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if PRAGMA_IMPORT
  39. #pragma import on
  40. #endif
  41.  
  42. #if PRAGMA_STRUCT_ALIGN
  43.     #pragma options align=power
  44. #elif PRAGMA_STRUCT_PACKPUSH
  45.     #pragma pack(push, 2)
  46. #elif PRAGMA_STRUCT_PACK
  47.     #pragma pack(2)
  48. #endif
  49.  
  50. #if TARGET_CPU_PPC
  51. #define MPCopyrightNotice                                \
  52.     "Copyright © 1995, 1996 DayStar Digital, Inc.\n"            \
  53.     "Portions Copyright © 1995 Apple Computer, Inc.\n"
  54. #define MPLibraryName "MPLibrary"
  55. #define MPLibraryCName MPLibraryName
  56. #define MPLibraryPName "\p" MPLibraryName
  57. #define MP_API_Version "1.4"
  58.  
  59. enum {
  60.     MPLibrary_MajorVersion        = 1,
  61.     MPLibrary_MinorVersion        = 4,
  62.     MPLibrary_Release            = 1,
  63.     MPLibrary_DevelopmentRevision = 2
  64. };
  65.  
  66. typedef struct OpaqueMPTaskID*             MPTaskID;
  67. typedef struct OpaqueMPQueueID*         MPQueueID;
  68. typedef struct OpaqueMPSemaphoreID*     MPSemaphoreID;
  69. typedef struct OpaqueMPCriticalRegionID*  MPCriticalRegionID;
  70. typedef UInt32                             MPSemaphoreCount;
  71. typedef UInt32                             MPTaskOptions;
  72. typedef CALLBACK_API_C( OSStatus , TaskProc )(void *parameter);
  73. typedef CALLBACK_API_C( void *, MPRemoteProcedure )(void *parameter);
  74. typedef CALLBACK_API_C( void , MPPrintfHandler )(MPTaskID taskID, const char *format, va_list args);
  75.  
  76. enum {
  77.     kDurationImmediate            = 0L,
  78.     kDurationForever            = 0x7FFFFFFF
  79. };
  80.  
  81.  
  82. enum {
  83.     kMPNoID                        = 0
  84. };
  85.  
  86.  
  87. #define MPLibraryIsLoaded()        \
  88.   ( ( (UInt32)_MPIsFullyInitialized != (UInt32)kUnresolvedCFragSymbolAddress ) \
  89.    && _MPIsFullyInitialized() )
  90.  
  91.  
  92. EXTERN_API_C( UInt32 )
  93. MPProcessors                    (void);
  94.  
  95. EXTERN_API_C( OSStatus )
  96. MPCreateTask                    (TaskProc                 entryPoint,
  97.                                  void *                    parameter,
  98.                                  ByteCount                 stackSize,
  99.                                  MPQueueID                 notifyQueue,
  100.                                  void *                    terminationParameter1,
  101.                                  void *                    terminationParameter2,
  102.                                  MPTaskOptions             options,
  103.                                  MPTaskID *                task);
  104.  
  105.  
  106. EXTERN_API_C( OSStatus )
  107. MPTerminateTask                    (MPTaskID                 task,
  108.                                  OSStatus                 terminationStatus);
  109.  
  110.  
  111. EXTERN_API_C( void )
  112. MPExit                            (OSStatus                 status);
  113.  
  114.  
  115. EXTERN_API_C( MPTaskID )
  116. MPCurrentTaskID                    (void);
  117.  
  118.  
  119. EXTERN_API_C( void )
  120. MPYield                            (void);
  121.  
  122.  
  123. EXTERN_API_C( OSStatus )
  124. MPCreateQueue                    (MPQueueID *            queue);
  125.  
  126.  
  127. EXTERN_API_C( OSStatus )
  128. MPDeleteQueue                    (MPQueueID                 queue);
  129.  
  130.  
  131. EXTERN_API_C( OSStatus )
  132. MPNotifyQueue                    (MPQueueID                 queue,
  133.                                  void *                    param1,
  134.                                  void *                    param2,
  135.                                  void *                    param3);
  136.  
  137.  
  138. EXTERN_API_C( OSStatus )
  139. MPWaitOnQueue                    (MPQueueID                 queue,
  140.                                  void **                param1,
  141.                                  void **                param2,
  142.                                  void **                param3,
  143.                                  Duration                 timeout);
  144.  
  145.  
  146. EXTERN_API_C( OSStatus )
  147. MPCreateSemaphore                (MPSemaphoreCount         maximumValue,
  148.                                  MPSemaphoreCount         initialValue,
  149.                                  MPSemaphoreID *        semaphore);
  150.  
  151.  
  152. #define MPCreateBinarySemaphore(semaphore) \
  153.         MPCreateSemaphore(1, 1, (semaphore))
  154.  
  155. EXTERN_API_C( OSStatus )
  156. MPWaitOnSemaphore                (MPSemaphoreID             semaphore,
  157.                                  Duration                 timeout);
  158.  
  159.  
  160. EXTERN_API_C( OSStatus )
  161. MPSignalSemaphore                (MPSemaphoreID             semaphore);
  162.  
  163.  
  164. EXTERN_API_C( OSStatus )
  165. MPDeleteSemaphore                (MPSemaphoreID             semaphore);
  166.  
  167.  
  168. EXTERN_API_C( OSStatus )
  169. MPCreateCriticalRegion            (MPCriticalRegionID *    criticalRegion);
  170.  
  171.  
  172. EXTERN_API_C( OSStatus )
  173. MPEnterCriticalRegion            (MPCriticalRegionID     criticalRegion,
  174.                                  Duration                 timeout);
  175.  
  176.  
  177. EXTERN_API_C( OSStatus )
  178. MPExitCriticalRegion            (MPCriticalRegionID     criticalRegion);
  179.  
  180.  
  181. EXTERN_API_C( OSStatus )
  182. MPDeleteCriticalRegion            (MPCriticalRegionID     criticalRegion);
  183.  
  184.  
  185. EXTERN_API_C( LogicalAddress )
  186. MPAllocate                        (ByteCount                 size);
  187.  
  188. EXTERN_API_C( void )
  189. MPFree                            (LogicalAddress         object);
  190.  
  191.  
  192. EXTERN_API_C( void )
  193. MPBlockCopy                        (LogicalAddress         sourcePtr,
  194.                                  LogicalAddress         destPtr,
  195.                                  ByteCount                 blockSize);
  196.  
  197.  
  198. /**************************************************************************
  199.  *
  200.  *    MPTaskIsToolboxSafe() and MPRPC() were functions added by DayStar. 
  201.  *    The 1.4 MPLibrary exports the names with an underscore prefix. 
  202.  *    To work around this, #defines have been added to automatically
  203.  *    add the underscore.
  204.  *
  205.  */
  206.  
  207. #define    MPTaskIsToolboxSafe        _MPTaskIsToolboxSafe
  208. #define    MPRPC                    _MPRPC
  209.  
  210. /* 
  211.     MPTaskIsToolboxSafe() allows routines which are otherwise unaware that 
  212.     they are being called from an MP task to check to see if it is permissible
  213.     to make a call to the Macintosh toolbox.  (It is okay to make toolbox 
  214.     calls only if the routine is not being called from an MP task).
  215. */
  216. EXTERN_API_C( Boolean )
  217. MPTaskIsToolboxSafe                (MPTaskID                 task);
  218.  
  219. /*
  220.     MPRPC() calls its MPRemoteProcedure parameter in the application's main 
  221.     thread when the app next calls WaitNextEvent, EventAvail, SystemTask, 
  222.     MPYield, MPWaitOnQueue, MPWaitOnSemaphore, or MPEnterCriticalRegion. The  
  223.     return value of the MPRemoteProcedure is returned as the result of MPRPC.  
  224.     The MPRemoteProcedure function can call any toolbox function except  
  225.     SystemTask (or anything that calls it).
  226. */
  227. EXTERN_API_C( void *)
  228. MPRPC                            (MPRemoteProcedure         theProc,
  229.                                  void *                    parameter);
  230.  
  231.  
  232.  
  233. /**************************************************************************
  234.  *
  235.  *    The following routines were added by DayStar for debugging purposes.
  236.  *    You should not use these in shipping products.  You can tell which
  237.  *    functions are for debugging only because they begin with an underscore
  238.  *
  239.  */
  240. EXTERN_API_C( Boolean )
  241. _MPIsFullyInitialized            (void);
  242.  
  243.  
  244. /*
  245.     MPAllocateSys() does the same thing as MPAllocate() except the memory
  246.     is allocated from the system heap.
  247. */
  248. EXTERN_API_C( LogicalAddress )
  249. _MPAllocateSys                    (ByteCount                 size);
  250.  
  251.  
  252. EXTERN_API_C( Boolean )
  253. _MPLibraryIsCompatible            (const char *            versionCString,
  254.                                  UInt32                 major,
  255.                                  UInt32                 minor,
  256.                                  UInt32                 release,
  257.                                  UInt32                 revision);
  258.  
  259. /*
  260.     MPLibraryVersion() retrieves the hardcoded version information built into
  261.     the currently active Multiprocessing API Library.
  262. */
  263. EXTERN_API_C( void )
  264. _MPLibraryVersion                (const char **            versionCString,
  265.                                  UInt32 *                major,
  266.                                  UInt32 *                minor,
  267.                                  UInt32 *                release,
  268.                                  UInt32 *                revision);
  269.  
  270. EXTERN_API_C( void )
  271. _MPInitializePrintf                (MPPrintfHandler         pfn);
  272.  
  273. EXTERN_API_C( void )
  274. _MPPrintf                        (const char *            format,
  275.                                  ...);
  276.  
  277.  
  278. /*
  279.      MPDebugStr() works just like DebugStr() except that it is safe
  280.     to call it from an MP task.
  281. */
  282. EXTERN_API_C( void )
  283. _MPDebugStr                        (ConstStr255Param         msg);
  284.  
  285. /*
  286.  
  287.     MPStatusPString() and MPStatusCString() provide a way to translate an OSStatus
  288.     value returned from one of the MP API calls into either a Pascal string or a
  289.     C string.  Thus, if an MPLibrary function returns an error then the application
  290.     (not a task) could use the following:
  291.  
  292.     status = MPxxx( function_params );
  293.     DebugStr( MPStatusPString( status ) );
  294.     
  295. */
  296. EXTERN_API_C( StringPtr )
  297. _MPStatusPString                (OSStatus                 status);
  298.  
  299. EXTERN_API_C( const char *)
  300. _MPStatusCString                (OSStatus                 status);
  301.  
  302.  
  303. #endif  /* TARGET_CPU_PPC */
  304.  
  305.  
  306. #if PRAGMA_STRUCT_ALIGN
  307.     #pragma options align=reset
  308. #elif PRAGMA_STRUCT_PACKPUSH
  309.     #pragma pack(pop)
  310. #elif PRAGMA_STRUCT_PACK
  311.     #pragma pack()
  312. #endif
  313.  
  314. #ifdef PRAGMA_IMPORT_OFF
  315. #pragma import off
  316. #elif PRAGMA_IMPORT
  317. #pragma import reset
  318. #endif
  319.  
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323.  
  324. #endif /* __MULTIPROCESSING__ */
  325.  
  326.